/*
 * 
 * 
 * 
 */

package sheep.model;

/////////////////////////////////////////////////////////////////////////////
import java.awt.Image;

/////////////////////////////////////////////////////////////////////////////
import java.util.LinkedList;

/**
 *
 * @author geek
 */
public class WorkGroup {

  /////////////////////////////////////////////////////////////////////////////
  
  // Numerotation des groupes
  private static int number=0;
  private int id;
  
  public static int workGroupTabLength = 3;
  
  private int nbUsers=0;
  
  // Nom de l'utilisateur
  private String name;
  
  // Image associee
  private Image picture;
  private String pictureURL;
  
  private LinkedList<Worker> workersList;

  /////////////////////////////////////////////////////////////////////////////
  // Constructors
  public WorkGroup(String name, String pictureURL){
    this.name = name;
    this.pictureURL = pictureURL;
    this.number++;
    this.id = this.number;
    workersList = new LinkedList<Worker>();
  }
  
  /////////////////////////////////////////////////////////////////////////////
  // Getters & Setters
  public int getId() {
    return id;
  }
  
  public void setId(int id) { this.id = id; }

  public String getName() {
    return name;
  }

  public void setName(String Name) {
    this.name = Name;
  }

  public Image getPicture() {
    return picture;
  }

  public void setPicture(Image picture) {
    this.picture = picture;
  }

  public LinkedList<Worker> getWorkersList() {
    return workersList;
  }
  
  public void clearWorkers() {
    this.workersList.clear();
    this.nbUsers = 0;
  }

  public void setWorkersList(LinkedList<Worker> workersList) {
    this.workersList = workersList;
  }
  
  public Object[] getWorkGroupTab() { return new Object[]{this.id, this.name, this.nbUsers}; }
  
  public Object[][] getWorkersTab() {
    Object[][] result = new Object [workersList.size()][Worker.workerTabLength];
    int i=0;
    for(Worker w : workersList) {
      result[i] = w.getWorkerTab();
      i++;
    }
    
    return result;
  }
  
  /////////////////////////////////////////////////////////////////////////////
  
  public void addWorker(Worker w) {
    this.workersList.add(w);
    this.nbUsers++;
  }
  
  public Worker getWorker(Object id) {
    Worker worker = null;
    
    for(Worker w : this.workersList)
      if(w.getId() == id)
        worker = w;
  
    return worker;
  }
  
  public void removeWorker(Worker w) {
    this.workersList.remove(w);
    this.nbUsers--;
  }
  
  public boolean hasWorker(Worker w) {
    for(Worker w2 : workersList) {
      if(w2 == w)
        return true;
    }
    
    return false;
  }

  public String getPictureURL() {
    return pictureURL;
  }

  public void setPictureURL(String pictureURL) {
    this.pictureURL = pictureURL;
  }
  
}

/////////////////////////////////////////////////////////////////////////////